package com.tust.app.service.impl;

import com.tust.app.dao.SourceMapper;
import com.tust.app.domain.Source;
import com.tust.app.service.SourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class SourceServiceImpl implements SourceService {

    @Autowired
    private SourceMapper sourceMapper;

    @Override
    public List<Source> sourceList() {
        return sourceMapper.selectAllSource();
    }

    @Override
    public List<Source> findAll() {
        return sourceMapper.selectAllSource();
    }

    @Override
    public Source findById(Integer id) {
        return sourceMapper.selectSourceById(id);
    }

    @Override
    public void insert(Source source) {
        sourceMapper.writeSource(source);
    }

    @Override
    public boolean modifySource(Source source) {
        return sourceMapper.updateSourceById(source);
    }

    @Override
    public List<Source> search(String filename) {
        if (filename != null && filename.length() > 0) {
            return sourceMapper.selectSourceByFilename(filename);
        } else {
            return Collections.emptyList();
        }
    }

    @Override
    public boolean delSource(Integer id) {
        return sourceMapper.deleteSourceById(id);
    }

    @Override
    public List<Source> getAllSources() {
        return sourceMapper.selectAllSource();
    }
}